/*
 * @Author: xuranXYS
 * @LastEditTime: 2024-01-02 18:54:52
 * @GitHub: www.github.com/xiaoxustudio
 * @WebSite: www.xiaoxustudio.top
 * @Description: By xuranXYS
 */
/**
 * @description: 左侧按钮组
 * 开源：https://gitee.com/xiaoxu1111/bootstrap-side-buttons
 * made with xuran
 * @param {*} obj
 * @return {*}
 */
var Hsb = function (obj, events) {
    const { buttons, dom, pagemax } = obj // 对象
    events = events || {} // 事件
    if (buttons instanceof Array && dom instanceof HTMLElement) {
        let pm = (pagemax >= 4 ? pagemax : pagemax + 3)
        dom.style.position = "fixed"
        dom.style.width = pm * 20 + "px"
        dom.style.height = pm * 20
        dom.style.top = "50%"
        dom.style.left = "2%"
        dom.style.overflow = "scroll"
        dom.classList.add("row")
        for (let i = 0; i < buttons.length; i++) {
            let domv = document.createElement("button")
            domv.classList.add("btn")
            let target = buttons[i]
            if (target.html) {
                domv.innerHTML = target.content || "按钮" + i
            } else {
                domv.innerText = target.content || "按钮" + i
            }
            if (target.instance instanceof Function) {
                target.instance.call(domv, this)
            }
            dom.appendChild(domv)
            dom.style.height = pm * domv.getBoundingClientRect().height
            dom.style.width = pm * domv.getBoundingClientRect().width
            if (pagemax - 1 == i) {
                break
            }
        }
        return this
    }
    return false
}